SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE DATABASE CBE
GO
USE CBE
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Localidades]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Localidades](
	[Id_Localidades] [uniqueidentifier] NOT NULL,
	[CodigoPostal] [varchar](50) NOT NULL,
	[Descripcion] [varchar](50) NULL,
 CONSTRAINT [PK_Localidades] PRIMARY KEY CLUSTERED 
(
	[Id_Localidades] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Provincias]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Provincias](
	[Id_Provincia] [uniqueidentifier] NOT NULL,
	[Descripcion] [varchar](50) NOT NULL,
 CONSTRAINT [PK_Provincias] PRIMARY KEY CLUSTERED 
(
	[Id_Provincia] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TiposDocumentos]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TiposDocumentos](
	[ID_TipoDocumento] [uniqueidentifier] NOT NULL,
	[Descripcion] [varchar](50) NULL,
 CONSTRAINT [PK_TiposDocumentos] PRIMARY KEY CLUSTERED 
(
	[ID_TipoDocumento] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Servicios]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Servicios](
	[ID_Servicio] [uniqueidentifier] NOT NULL,
	[Codigo] [varchar](50) NOT NULL,
	[Descripcion] [varchar](50) NULL,
	[Precio] [decimal](18, 2) NULL,
	[DuracionAproximadaMinutos] [int] NULL,
 CONSTRAINT [PK_Servicios] PRIMARY KEY CLUSTERED 
(
	[ID_Servicio] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Promociones]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Promociones](
	[ID_Promocion] [uniqueidentifier] NOT NULL,
	[Codigo] [varchar](50) NULL,
	[Descripcion] [varchar](50) NULL,
	[Bonificacion] [decimal](18, 2) NULL,
	[FechaInicio] [datetime] NULL,
	[FechaFin] [datetime] NULL,
	[NotificaPorMail] [bit] NULL,
	[NotificaPorSMS] [bit] NULL,
	[EsPromocionPublica] [bit] NULL,
 CONSTRAINT [PK_Promociones] PRIMARY KEY CLUSTERED 
(
	[ID_Promocion] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Dias]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Dias](
	[ID_Dia] [uniqueidentifier] NOT NULL,
	[Descripcion] [nvarchar](50) NULL,
	[FechaReferenci] [datetime] NULL,
 CONSTRAINT [PK_Dias] PRIMARY KEY CLUSTERED 
(
	[ID_Dia] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Proveedores]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Proveedores](
	[ID_Proveedor] [uniqueidentifier] NOT NULL,
	[RazonSocial] [varchar](50) NULL,
	[ID_TipoDocumento] [uniqueidentifier] NULL,
	[NumeroDocumento] [varchar](50) NULL,
	[FechaConstitucion] [datetime] NULL,
	[ID_Provincia] [uniqueidentifier] NULL,
	[ID_Localidad] [uniqueidentifier] NULL,
	[CodigoPostal] [varchar](50) NULL,
	[Calle] [varchar](50) NULL,
	[Numero] [varchar](50) NULL,
	[Piso] [int] NULL,
	[Departamento] [int] NULL,
	[Telefono] [varchar](50) NULL,
	[Mail] [varchar](50) NULL,
	[NombreContacto] [varchar](50) NULL,
	[Observaciones] [varchar](50) NULL,
 CONSTRAINT [PK_Proveedores] PRIMARY KEY CLUSTERED 
(
	[ID_Proveedor] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Empleados]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Empleados](
	[ID_Empleado] [uniqueidentifier] NOT NULL,
	[Apellido] [varchar](50) NULL,
	[Nombre] [varchar](50) NULL,
	[ID_TipoDocumento] [uniqueidentifier] NOT NULL,
	[NumeroDocumento] [nchar](10) NOT NULL,
	[FechaNacimiento] [datetime] NOT NULL,
	[ID_Provincia] [uniqueidentifier] NOT NULL,
	[ID_Localidad] [uniqueidentifier] NOT NULL,
	[CodigoPostal] [varchar](50) NOT NULL,
	[Calle] [varchar](50) NOT NULL,
	[Numero] [varchar](50) NOT NULL,
	[Piso] [int] NULL,
	[Departamento] [int] NULL,
	[AclaracionDomicilio] [varchar](50) NULL,
	[Telefono] [varchar](50) NOT NULL,
	[Mail] [varchar](50) NOT NULL,
 CONSTRAINT [PK_Empleados] PRIMARY KEY CLUSTERED 
(
	[ID_Empleado] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Clientes]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Clientes](
	[ID_Cliente] [uniqueidentifier] NOT NULL,
	[Apellido] [varchar](50) NULL,
	[Nombre] [varchar](50) NULL,
	[ID_TipoDocumento] [uniqueidentifier] NULL,
	[NumeroDocumento] [varchar](50) NULL,
	[FechaNacimiento] [datetime] NULL,
	[ID_Provincia] [uniqueidentifier] NULL,
	[ID_Localidad] [uniqueidentifier] NULL,
	[CodigoPostal] [varchar](50) NULL,
	[Calle] [varchar](50) NULL,
	[Numero] [varchar](50) NULL,
	[Piso] [int] NULL,
	[Departamento] [int] NULL,
	[AclaracionDomicilio] [varchar](50) NULL,
	[Telefono] [varchar](50) NULL,
	[Mail] [varchar](50) NULL,
 CONSTRAINT [PK_Clientes] PRIMARY KEY CLUSTERED 
(
	[ID_Cliente] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ServiciosVenta]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ServiciosVenta](
	[ID_ServicioVenta] [uniqueidentifier] NOT NULL,
	[ID_Venta] [uniqueidentifier] NOT NULL,
	[ID_Servicio] [uniqueidentifier] NOT NULL,
	[ID_Empleado] [uniqueidentifier] NOT NULL,
	[ImporteServicio] [decimal](18, 2) NULL,
 CONSTRAINT [PK_ServiciosVenta] PRIMARY KEY CLUSTERED 
(
	[ID_ServicioVenta] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Turnos]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Turnos](
	[ID_Turno] [uniqueidentifier] NOT NULL,
	[ID_Cliente] [uniqueidentifier] NOT NULL,
	[ID_Servicio] [uniqueidentifier] NOT NULL,
	[ID_Empleado] [uniqueidentifier] NOT NULL,
	[Fecha] [datetime] NULL,
	[Hora] [datetime] NULL,
 CONSTRAINT [PK_Turnos] PRIMARY KEY CLUSTERED 
(
	[ID_Turno] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ServiciosPromocion]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ServiciosPromocion](
	[ID_ServicioPromocion] [uniqueidentifier] NOT NULL,
	[ID_Servicio] [uniqueidentifier] NOT NULL,
	[ID_Promocion] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_ServiciosPromocion] PRIMARY KEY CLUSTERED 
(
	[ID_ServicioPromocion] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ProductosServicio]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ProductosServicio](
	[ID_ProductoServicio] [uniqueidentifier] NOT NULL,
	[ID_Producto] [uniqueidentifier] NOT NULL,
	[Cantidad] [int] NULL,
	[ID_Servicio] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_ProductosServicio] PRIMARY KEY CLUSTERED 
(
	[ID_ProductoServicio] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ProductosCompra]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ProductosCompra](
	[ID_ProductoCompra] [uniqueidentifier] NOT NULL,
	[ID_Producto] [uniqueidentifier] NULL,
	[Cantidad] [int] NULL,
	[ID_Compra] [uniqueidentifier] NULL,
 CONSTRAINT [PK_ProductosCompra] PRIMARY KEY CLUSTERED 
(
	[ID_ProductoCompra] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ProductosVenta]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ProductosVenta](
	[ID_ProductoVenta] [uniqueidentifier] NOT NULL,
	[ID_Producto] [uniqueidentifier] NOT NULL,
	[Cantidad] [int] NULL,
	[Importe] [decimal](18, 2) NULL,
	[ID_Venta] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_ProductosVenta] PRIMARY KEY CLUSTERED 
(
	[ID_ProductoVenta] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PromocionesVenta]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PromocionesVenta](
	[ID_PromocionVenta] [uniqueidentifier] NOT NULL,
	[ID_Promocion] [uniqueidentifier] NOT NULL,
	[ID_Venta] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_PromocionesVenta] PRIMARY KEY CLUSTERED 
(
	[ID_PromocionVenta] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Ventas]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Ventas](
	[ID_Venta] [uniqueidentifier] NOT NULL,
	[ID_Cliente] [uniqueidentifier] NOT NULL,
	[ID_Turno] [uniqueidentifier] NOT NULL,
	[FechaVenta] [datetime] NULL,
	[Importe] [decimal](18, 2) NULL,
	[Vuelto] [decimal](18, 2) NULL,
 CONSTRAINT [PK_Ventas] PRIMARY KEY CLUSTERED 
(
	[ID_Venta] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DiasPromocion]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DiasPromocion](
	[ID_DiaPromocio] [uniqueidentifier] NOT NULL,
	[ID_Dia] [uniqueidentifier] NOT NULL,
	[ID_Promocion] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_DiasPromocion] PRIMARY KEY CLUSTERED 
(
	[ID_DiaPromocio] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ClientesPromocion]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ClientesPromocion](
	[ID_ClientePromocion] [uniqueidentifier] NOT NULL,
	[ID_Cliente] [uniqueidentifier] NOT NULL,
	[ID_Promocion] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_ClientesPromocion] PRIMARY KEY CLUSTERED 
(
	[ID_ClientePromocion] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Productos]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Productos](
	[ID_Producto] [uniqueidentifier] NOT NULL,
	[Codigo] [varchar](50) NULL,
	[Marca] [varchar](50) NULL,
	[Presentacion] [varchar](50) NULL,
	[FechaIncorporacion] [datetime] NULL,
	[ID_Proveedor] [uniqueidentifier] NULL,
	[Stock] [int] NULL,
	[PrecioUnitario] [decimal](18, 2) NULL,
 CONSTRAINT [PK_Productos] PRIMARY KEY CLUSTERED 
(
	[ID_Producto] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Compras]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Compras](
	[ID_Compra] [uniqueidentifier] NOT NULL,
	[NroComprobante] [varchar](50) NOT NULL,
	[FechaRecepcion] [datetime] NOT NULL,
	[ID_Proveedor] [uniqueidentifier] NOT NULL,
	[ImporteCompra] [decimal](18, 2) NOT NULL,
 CONSTRAINT [PK_Compras] PRIMARY KEY CLUSTERED 
(
	[ID_Compra] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Proveedores_Localidades]') AND parent_object_id = OBJECT_ID(N'[dbo].[Proveedores]'))
ALTER TABLE [dbo].[Proveedores]  WITH CHECK ADD  CONSTRAINT [FK_Proveedores_Localidades] FOREIGN KEY([ID_Localidad])
REFERENCES [dbo].[Localidades] ([Id_Localidades])
GO
ALTER TABLE [dbo].[Proveedores] CHECK CONSTRAINT [FK_Proveedores_Localidades]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Proveedores_Provincias]') AND parent_object_id = OBJECT_ID(N'[dbo].[Proveedores]'))
ALTER TABLE [dbo].[Proveedores]  WITH CHECK ADD  CONSTRAINT [FK_Proveedores_Provincias] FOREIGN KEY([ID_Provincia])
REFERENCES [dbo].[Provincias] ([Id_Provincia])
GO
ALTER TABLE [dbo].[Proveedores] CHECK CONSTRAINT [FK_Proveedores_Provincias]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Proveedores_TiposDocumentos]') AND parent_object_id = OBJECT_ID(N'[dbo].[Proveedores]'))
ALTER TABLE [dbo].[Proveedores]  WITH CHECK ADD  CONSTRAINT [FK_Proveedores_TiposDocumentos] FOREIGN KEY([ID_TipoDocumento])
REFERENCES [dbo].[TiposDocumentos] ([ID_TipoDocumento])
GO
ALTER TABLE [dbo].[Proveedores] CHECK CONSTRAINT [FK_Proveedores_TiposDocumentos]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Empleados_Localidades]') AND parent_object_id = OBJECT_ID(N'[dbo].[Empleados]'))
ALTER TABLE [dbo].[Empleados]  WITH CHECK ADD  CONSTRAINT [FK_Empleados_Localidades] FOREIGN KEY([ID_Localidad])
REFERENCES [dbo].[Localidades] ([Id_Localidades])
GO
ALTER TABLE [dbo].[Empleados] CHECK CONSTRAINT [FK_Empleados_Localidades]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Empleados_Provincias]') AND parent_object_id = OBJECT_ID(N'[dbo].[Empleados]'))
ALTER TABLE [dbo].[Empleados]  WITH CHECK ADD  CONSTRAINT [FK_Empleados_Provincias] FOREIGN KEY([ID_Provincia])
REFERENCES [dbo].[Provincias] ([Id_Provincia])
GO
ALTER TABLE [dbo].[Empleados] CHECK CONSTRAINT [FK_Empleados_Provincias]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Empleados_TiposDocumentos]') AND parent_object_id = OBJECT_ID(N'[dbo].[Empleados]'))
ALTER TABLE [dbo].[Empleados]  WITH CHECK ADD  CONSTRAINT [FK_Empleados_TiposDocumentos] FOREIGN KEY([ID_TipoDocumento])
REFERENCES [dbo].[TiposDocumentos] ([ID_TipoDocumento])
GO
ALTER TABLE [dbo].[Empleados] CHECK CONSTRAINT [FK_Empleados_TiposDocumentos]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Clientes_Localidades]') AND parent_object_id = OBJECT_ID(N'[dbo].[Clientes]'))
ALTER TABLE [dbo].[Clientes]  WITH CHECK ADD  CONSTRAINT [FK_Clientes_Localidades] FOREIGN KEY([ID_Localidad])
REFERENCES [dbo].[Localidades] ([Id_Localidades])
GO
ALTER TABLE [dbo].[Clientes] CHECK CONSTRAINT [FK_Clientes_Localidades]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Clientes_Provincias]') AND parent_object_id = OBJECT_ID(N'[dbo].[Clientes]'))
ALTER TABLE [dbo].[Clientes]  WITH CHECK ADD  CONSTRAINT [FK_Clientes_Provincias] FOREIGN KEY([ID_Provincia])
REFERENCES [dbo].[Provincias] ([Id_Provincia])
GO
ALTER TABLE [dbo].[Clientes] CHECK CONSTRAINT [FK_Clientes_Provincias]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Clientes_TiposDocumentos]') AND parent_object_id = OBJECT_ID(N'[dbo].[Clientes]'))
ALTER TABLE [dbo].[Clientes]  WITH CHECK ADD  CONSTRAINT [FK_Clientes_TiposDocumentos] FOREIGN KEY([ID_TipoDocumento])
REFERENCES [dbo].[TiposDocumentos] ([ID_TipoDocumento])
GO
ALTER TABLE [dbo].[Clientes] CHECK CONSTRAINT [FK_Clientes_TiposDocumentos]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ServiciosVenta_Empleados]') AND parent_object_id = OBJECT_ID(N'[dbo].[ServiciosVenta]'))
ALTER TABLE [dbo].[ServiciosVenta]  WITH CHECK ADD  CONSTRAINT [FK_ServiciosVenta_Empleados] FOREIGN KEY([ID_Empleado])
REFERENCES [dbo].[Empleados] ([ID_Empleado])
GO
ALTER TABLE [dbo].[ServiciosVenta] CHECK CONSTRAINT [FK_ServiciosVenta_Empleados]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ServiciosVenta_Servicios]') AND parent_object_id = OBJECT_ID(N'[dbo].[ServiciosVenta]'))
ALTER TABLE [dbo].[ServiciosVenta]  WITH CHECK ADD  CONSTRAINT [FK_ServiciosVenta_Servicios] FOREIGN KEY([ID_Servicio])
REFERENCES [dbo].[Servicios] ([ID_Servicio])
GO
ALTER TABLE [dbo].[ServiciosVenta] CHECK CONSTRAINT [FK_ServiciosVenta_Servicios]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ServiciosVenta_Ventas]') AND parent_object_id = OBJECT_ID(N'[dbo].[ServiciosVenta]'))
ALTER TABLE [dbo].[ServiciosVenta]  WITH CHECK ADD  CONSTRAINT [FK_ServiciosVenta_Ventas] FOREIGN KEY([ID_Venta])
REFERENCES [dbo].[Ventas] ([ID_Venta])
GO
ALTER TABLE [dbo].[ServiciosVenta] CHECK CONSTRAINT [FK_ServiciosVenta_Ventas]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Turnos_Clientes]') AND parent_object_id = OBJECT_ID(N'[dbo].[Turnos]'))
ALTER TABLE [dbo].[Turnos]  WITH CHECK ADD  CONSTRAINT [FK_Turnos_Clientes] FOREIGN KEY([ID_Cliente])
REFERENCES [dbo].[Clientes] ([ID_Cliente])
GO
ALTER TABLE [dbo].[Turnos] CHECK CONSTRAINT [FK_Turnos_Clientes]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Turnos_Empleados]') AND parent_object_id = OBJECT_ID(N'[dbo].[Turnos]'))
ALTER TABLE [dbo].[Turnos]  WITH CHECK ADD  CONSTRAINT [FK_Turnos_Empleados] FOREIGN KEY([ID_Empleado])
REFERENCES [dbo].[Empleados] ([ID_Empleado])
GO
ALTER TABLE [dbo].[Turnos] CHECK CONSTRAINT [FK_Turnos_Empleados]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Turnos_Servicios]') AND parent_object_id = OBJECT_ID(N'[dbo].[Turnos]'))
ALTER TABLE [dbo].[Turnos]  WITH CHECK ADD  CONSTRAINT [FK_Turnos_Servicios] FOREIGN KEY([ID_Servicio])
REFERENCES [dbo].[Servicios] ([ID_Servicio])
GO
ALTER TABLE [dbo].[Turnos] CHECK CONSTRAINT [FK_Turnos_Servicios]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ServiciosPromocion_Promociones]') AND parent_object_id = OBJECT_ID(N'[dbo].[ServiciosPromocion]'))
ALTER TABLE [dbo].[ServiciosPromocion]  WITH CHECK ADD  CONSTRAINT [FK_ServiciosPromocion_Promociones] FOREIGN KEY([ID_Promocion])
REFERENCES [dbo].[Promociones] ([ID_Promocion])
GO
ALTER TABLE [dbo].[ServiciosPromocion] CHECK CONSTRAINT [FK_ServiciosPromocion_Promociones]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ServiciosPromocion_Servicios]') AND parent_object_id = OBJECT_ID(N'[dbo].[ServiciosPromocion]'))
ALTER TABLE [dbo].[ServiciosPromocion]  WITH CHECK ADD  CONSTRAINT [FK_ServiciosPromocion_Servicios] FOREIGN KEY([ID_Servicio])
REFERENCES [dbo].[Servicios] ([ID_Servicio])
GO
ALTER TABLE [dbo].[ServiciosPromocion] CHECK CONSTRAINT [FK_ServiciosPromocion_Servicios]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProductosServicio_Productos]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProductosServicio]'))
ALTER TABLE [dbo].[ProductosServicio]  WITH CHECK ADD  CONSTRAINT [FK_ProductosServicio_Productos] FOREIGN KEY([ID_Producto])
REFERENCES [dbo].[Productos] ([ID_Producto])
GO
ALTER TABLE [dbo].[ProductosServicio] CHECK CONSTRAINT [FK_ProductosServicio_Productos]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProductosServicio_Servicios]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProductosServicio]'))
ALTER TABLE [dbo].[ProductosServicio]  WITH CHECK ADD  CONSTRAINT [FK_ProductosServicio_Servicios] FOREIGN KEY([ID_Servicio])
REFERENCES [dbo].[Servicios] ([ID_Servicio])
GO
ALTER TABLE [dbo].[ProductosServicio] CHECK CONSTRAINT [FK_ProductosServicio_Servicios]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProductosCompra_Compras]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProductosCompra]'))
ALTER TABLE [dbo].[ProductosCompra]  WITH CHECK ADD  CONSTRAINT [FK_ProductosCompra_Compras] FOREIGN KEY([ID_Compra])
REFERENCES [dbo].[Compras] ([ID_Compra])
GO
ALTER TABLE [dbo].[ProductosCompra] CHECK CONSTRAINT [FK_ProductosCompra_Compras]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProductosCompra_Productos]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProductosCompra]'))
ALTER TABLE [dbo].[ProductosCompra]  WITH CHECK ADD  CONSTRAINT [FK_ProductosCompra_Productos] FOREIGN KEY([ID_Producto])
REFERENCES [dbo].[Productos] ([ID_Producto])
GO
ALTER TABLE [dbo].[ProductosCompra] CHECK CONSTRAINT [FK_ProductosCompra_Productos]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProductosVenta_Productos]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProductosVenta]'))
ALTER TABLE [dbo].[ProductosVenta]  WITH CHECK ADD  CONSTRAINT [FK_ProductosVenta_Productos] FOREIGN KEY([ID_Producto])
REFERENCES [dbo].[Productos] ([ID_Producto])
GO
ALTER TABLE [dbo].[ProductosVenta] CHECK CONSTRAINT [FK_ProductosVenta_Productos]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProductosVenta_Ventas]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProductosVenta]'))
ALTER TABLE [dbo].[ProductosVenta]  WITH CHECK ADD  CONSTRAINT [FK_ProductosVenta_Ventas] FOREIGN KEY([ID_Venta])
REFERENCES [dbo].[Ventas] ([ID_Venta])
GO
ALTER TABLE [dbo].[ProductosVenta] CHECK CONSTRAINT [FK_ProductosVenta_Ventas]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PromocionesVenta_Promociones]') AND parent_object_id = OBJECT_ID(N'[dbo].[PromocionesVenta]'))
ALTER TABLE [dbo].[PromocionesVenta]  WITH CHECK ADD  CONSTRAINT [FK_PromocionesVenta_Promociones] FOREIGN KEY([ID_Promocion])
REFERENCES [dbo].[Promociones] ([ID_Promocion])
GO
ALTER TABLE [dbo].[PromocionesVenta] CHECK CONSTRAINT [FK_PromocionesVenta_Promociones]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PromocionesVenta_Ventas]') AND parent_object_id = OBJECT_ID(N'[dbo].[PromocionesVenta]'))
ALTER TABLE [dbo].[PromocionesVenta]  WITH CHECK ADD  CONSTRAINT [FK_PromocionesVenta_Ventas] FOREIGN KEY([ID_Venta])
REFERENCES [dbo].[Ventas] ([ID_Venta])
GO
ALTER TABLE [dbo].[PromocionesVenta] CHECK CONSTRAINT [FK_PromocionesVenta_Ventas]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Ventas_Clientes]') AND parent_object_id = OBJECT_ID(N'[dbo].[Ventas]'))
ALTER TABLE [dbo].[Ventas]  WITH CHECK ADD  CONSTRAINT [FK_Ventas_Clientes] FOREIGN KEY([ID_Cliente])
REFERENCES [dbo].[Clientes] ([ID_Cliente])
GO
ALTER TABLE [dbo].[Ventas] CHECK CONSTRAINT [FK_Ventas_Clientes]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Ventas_Turnos]') AND parent_object_id = OBJECT_ID(N'[dbo].[Ventas]'))
ALTER TABLE [dbo].[Ventas]  WITH CHECK ADD  CONSTRAINT [FK_Ventas_Turnos] FOREIGN KEY([ID_Turno])
REFERENCES [dbo].[Turnos] ([ID_Turno])
GO
ALTER TABLE [dbo].[Ventas] CHECK CONSTRAINT [FK_Ventas_Turnos]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DiasPromocion_Dias]') AND parent_object_id = OBJECT_ID(N'[dbo].[DiasPromocion]'))
ALTER TABLE [dbo].[DiasPromocion]  WITH CHECK ADD  CONSTRAINT [FK_DiasPromocion_Dias] FOREIGN KEY([ID_Dia])
REFERENCES [dbo].[Dias] ([ID_Dia])
GO
ALTER TABLE [dbo].[DiasPromocion] CHECK CONSTRAINT [FK_DiasPromocion_Dias]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DiasPromocion_Promociones]') AND parent_object_id = OBJECT_ID(N'[dbo].[DiasPromocion]'))
ALTER TABLE [dbo].[DiasPromocion]  WITH CHECK ADD  CONSTRAINT [FK_DiasPromocion_Promociones] FOREIGN KEY([ID_Promocion])
REFERENCES [dbo].[Promociones] ([ID_Promocion])
GO
ALTER TABLE [dbo].[DiasPromocion] CHECK CONSTRAINT [FK_DiasPromocion_Promociones]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ClientesPromocion_Clientes]') AND parent_object_id = OBJECT_ID(N'[dbo].[ClientesPromocion]'))
ALTER TABLE [dbo].[ClientesPromocion]  WITH CHECK ADD  CONSTRAINT [FK_ClientesPromocion_Clientes] FOREIGN KEY([ID_Cliente])
REFERENCES [dbo].[Clientes] ([ID_Cliente])
GO
ALTER TABLE [dbo].[ClientesPromocion] CHECK CONSTRAINT [FK_ClientesPromocion_Clientes]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ClientesPromocion_Promociones]') AND parent_object_id = OBJECT_ID(N'[dbo].[ClientesPromocion]'))
ALTER TABLE [dbo].[ClientesPromocion]  WITH CHECK ADD  CONSTRAINT [FK_ClientesPromocion_Promociones] FOREIGN KEY([ID_Promocion])
REFERENCES [dbo].[Promociones] ([ID_Promocion])
GO
ALTER TABLE [dbo].[ClientesPromocion] CHECK CONSTRAINT [FK_ClientesPromocion_Promociones]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Productos_Proveedores]') AND parent_object_id = OBJECT_ID(N'[dbo].[Productos]'))
ALTER TABLE [dbo].[Productos]  WITH CHECK ADD  CONSTRAINT [FK_Productos_Proveedores] FOREIGN KEY([ID_Proveedor])
REFERENCES [dbo].[Proveedores] ([ID_Proveedor])
GO
ALTER TABLE [dbo].[Productos] CHECK CONSTRAINT [FK_Productos_Proveedores]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Compras_Proveedores]') AND parent_object_id = OBJECT_ID(N'[dbo].[Compras]'))
ALTER TABLE [dbo].[Compras]  WITH CHECK ADD  CONSTRAINT [FK_Compras_Proveedores] FOREIGN KEY([ID_Proveedor])
REFERENCES [dbo].[Proveedores] ([ID_Proveedor])
GO
ALTER TABLE [dbo].[Compras] CHECK CONSTRAINT [FK_Compras_Proveedores]
